import { Component ,OnInit} from '@angular/core';

@Component({
  selector: 'app-past-six-years',
  templateUrl: './past-six-years.component.html',
  styleUrls: ['./past-six-years.component.less']
})
export class PastSixYearsComponent implements OnInit{
  ngOnInit(): void {
    this.getFebruaryLastDay()
  }
  // 输出最近六年二月最后一天日期
  getFebruaryLastDay():void{
    let str:string=""
    let num:Date = new Date(); // 获取当前年
    let timeList:Array<number> = []
    for (let index = 5; index >=0; index--) {
      timeList.push(num.getFullYear()-index)
    }
    for (let index = 0; index < timeList.length; index++) {
      if (this.IsLeapYear(timeList[index])) {
        str = String(timeList[index])+"-"+"02"+"-"+"29"
        console.log(str);
        str = ""
      }else{
        str = String(timeList[index])+"-"+"02"+"-"+"28"
        console.log(str);
        str = ""
      }
    }
  }
  // 判断是否闰年
  IsLeapYear(years:number){
    if(years%4==0&&years%100!==0||years%400===0){
      return true;
    }else{
        return false;//闰年返回true，不是闰年返回false；
    }
  }
}
